package com.fish.start.animation;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.fish.start.animation.Attr.AbstractWay;

public class AnimationSet {
	private static final String tag = AnimationSet.class.getSimpleName();
	private static final int MAX_ANIMATIONS = 5;
	private static final int MIN_ANIMATIONS = 0;
	public boolean mStopProduce = false;
	public boolean mNotingToDraw = false;
	private  List<AbstractWay> mAnimations = new ArrayList<AbstractWay>();
	public List<AbstractWay> getmAnimations() {
		return mAnimations;
	}
	public void setmAnimations(List<AbstractWay> mAnimations) {
		this.mAnimations = mAnimations;
	}
	public synchronized void push(AbstractWay aAnimationAttr){
		try{
			while (mAnimations.size() == MAX_ANIMATIONS) {
				Log.d(tag,"the container is full:"+mAnimations.size()+",push wait.");
				this.wait();
			}
			this.notify();
		}catch(InterruptedException  e){
			e.printStackTrace();
		}
		Log.d(tag,"add new animation to the container:"+mAnimations.size()+".");
		mAnimations.add(aAnimationAttr);
	}
	public synchronized AbstractWay pop(){
		try{
			while (mAnimations.size() == MIN_ANIMATIONS && !mStopProduce) {
				this.wait();
				Log.d(tag,"the container is empty:"+mAnimations.size()+",pop wait.");
			}
			this.notify();
		}catch(InterruptedException  e){
			e.printStackTrace();
		}
		if(mAnimations.size()>0){
			Log.d(tag,"pop an animation to the canvas:"+mAnimations.size()+".");
			return mAnimations.remove(0);
		}
		return null;
	}
	
	public synchronized void stopProduce(){
		Log.d(tag,"stop produce animation:"+mAnimations.size()+".");
		mStopProduce = true;
	}
	public synchronized boolean hasAnimation(){
		return mAnimations.size()>0;
	}
	public synchronized boolean onlyOneAnimation(){
		return mAnimations.size()==1;
	}
}
